package com.sh.personnel.util;

import org.springframework.security.crypto.bcrypt.BCrypt;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

/**
 * 密码工具类
 * @author 林思浩
 * @date 2020/03/14 17:20
 */
public class PwUtil {

    private static BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();

    /**
     * 密码加密
     * @param password
     * @return
     */
    public static String encrypt(String password) {
        return bCryptPasswordEncoder.encode(password);
    }

    /**
     * 校验密码
     * @param password
     * @param passwordEncode
     * @return
     */
    public static boolean matches(String password, String passwordEncode) {
        return BCrypt.checkpw(password, passwordEncode);
    }
}
